<template>
  <div style="background-color: #fff">
    <div>
      <homePage></homePage>
    </div>
    <div class="container">
      <div class="left">
        <el-menu :default-active="$route.path" @select="handleSelect">
          <el-menu-item index="/usercenter/userinfo">
            <i class="el-icon-user"></i>
            <span slot="title">个人信息</span>
          </el-menu-item>
          <el-menu-item index="/usercenter/usersecurity">
            <i class="el-icon-key"></i>
            <span slot="title">账号安全</span>
          </el-menu-item>
          <el-menu-item index="/usercenter/scholarmanage">
            <i class="el-icon-suitcase-1"></i>
            <span slot="title">门户管理</span>
          </el-menu-item>
          <el-menu-item index="/usercenter/collection">
            <i class="el-icon-collection-tag"></i>
            <span slot="title">收藏列表</span>
          </el-menu-item>
          <el-menu-item index="/usercenter/history">
            <i class="el-icon-time"></i>
            <span slot="title">浏览历史</span>
          </el-menu-item>
          <el-menu-item index="/usercenter/checkfollow">
            <i class="el-icon-user-solid"></i>
            <span slot="title">关注用户</span>
          </el-menu-item>
          <el-menu-item index="/usercenter/messagecenter">
            <i class="el-icon-bell"></i>
            <span slot="title">消息中心</span>
          </el-menu-item>
          <el-menu-item v-if="isAdmin" index="/usercenter/pendingreview">
            <i class="el-icon-edit-outline"></i>
            <span slot="title">审核事项</span>
          </el-menu-item>
        </el-menu>
      </div>
      <div class="right">
        <el-main><router-view /></el-main>
      </div>
    </div>
  </div>
</template>

<script>
import homePage from "../components/homePage.vue";
export default {
  name: "UserCenter",
  data() {
    return {
      isLogin: false,
      isAdmin: true,
    };
  },
  components: {
    homePage,
  },
  created() {
    this.getUserInfo();
    console.log(this.$route.path);
    if (this.$route.path == "/usercenter")
      this.$router.push("/usercenter/userinfo");
    // else{
    //   if(this.$route.path == "/usercenter/userinfo")
    //   this.
    // }
  },
  methods: {
    //请求用户的一些信息
    async getUserInfo() {
      await this.$axios({
        method: "get",
        url: "/api/getUserMsg",
      })
        .then((res) => {
          if (res.data.errno === 800001) {
            this.$router.push("/login");
          }
          this.isAdmin = res.data.backend_data.is_staff;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //路由跳转页面
    handleSelect(index) {
      this.$router.push(index);
    },
  },
};
</script>

<style scoped>
.right {
  display: inline-block;
}

.el-menu-item.is-active {
  color: #778dff;
}
.el-menu {
  height: 600px;
}
.left {
  vertical-align: top;
  margin: 20px 0;
  display: inline-block;
  width: 200px;
  /* outline: red 1px solid; */
}

.container {
  padding: 0 0 0 100px;
}
</style>
